#!/usr/bin/python


def digitHash(n):
	return "".join(sorted( list(str(n)) ));
	

def euler62():
	
	table={};
	x=1;
	while True:
		x+=1;
		cube=x**3;
		h=digitHash(cube);
		
		if( not h in table ):
			table[h]=(cube, 1);
		else:
			(scube, count)=table[h];
			if( count==4):
				return scube;
			table[h]=(scube, count+1);

	
print euler62();
			
		
